package com.qdu.bean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class bikeWritable implements WritableComparable<bikeWritable>{
    private String timeStamp;
    private int casual;
    private int registered;
    private int count;
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");


    public bikeWritable(int casual, int registered, int count) {
        this.casual = casual;
        this.registered = registered;
        this.count = count;
    }

    public bikeWritable(String date) {
        this.timeStamp = date;
    }
    public bikeWritable() {
        this.timeStamp="";
        this.casual=0;
        this.registered=0;
        this.count=0;
    }

    public int getCasual() {
        return casual;
    }

    public void setCasual(int casual) {
        this.casual = casual;
    }

    public int getRegistered() {
        return registered;
    }

    public void setRegistered(int registered) {
        this.registered = registered;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void set1(String date) {
        this.timeStamp=date;


    }
    public void set2(int casual, int registered, int count) {
        this.casual=casual;
        this.registered=registered;
        this.count=count;

    }
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(timeStamp);
        dataOutput.writeInt(casual);
        dataOutput.writeInt(registered);
        dataOutput.writeInt(count);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        timeStamp=dataInput.readUTF();
        casual=dataInput.readInt();
        registered=dataInput.readInt();
        count=dataInput.readInt();
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    @Override
    public String toString() {
        return casual+" "+registered+" "+count;
    }

    @Override
    public int compareTo(bikeWritable o) {
        try {
            long thisValue = sdf.parse(this.timeStamp).getTime();
            long thatValue=sdf.parse(o.timeStamp).getTime();
            return (thisValue<thatValue?-1:(thisValue == thatValue ? 0 : 1));//若this<that为1，是倒序，若this<that 为-1,是正序
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -2;
    }

}
